import tkinter as tk
window = tk.Tk()
window.title('my window')
window.geometry('500x500')

var1 = tk.StringVar()  # 开个变量var1
l = tk.Label(window, bg='yellow', width=4, textvariable=var1)
l.pack()


def print_selection():
    value = lb.get(lb.curselection())  # 光标选定的东西
    var1.set(value)


b = tk.Button(window, text='print selection', width=15, height=2, command=print_selection)
b.pack()

var2 = tk.StringVar()  # 开个变量var2
var2.set((11, 22, 33, 44))
lb = tk.Listbox(window, listvariable=var2)  # 供选择的项
list_items = [1, 2, 3, 4]
for item in list_items:
    lb.insert('end', item)
lb.insert(1, 'first')  # 增添进去，索引
lb.insert(2, 'second')
# lb.delete(2)  # 删除
lb.pack()
window.mainloop()

